package com.javasm.crm.service.marketingActivity.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javasm.crm.domin.entity.marketingActivity.GoodsInfo2;
import com.javasm.crm.domin.entity.marketingActivity.clinetClaim.findGood;
import com.javasm.crm.mapper.marketingActivity.GoodsInfoMapper2;
import com.javasm.crm.service.marketingActivity.GoodsInfoService2;
import com.javasm.crm.utils.page.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author llyp
 * @since 2021-07-16
 */
@Service
public class GoodsInfoServiceImpl2 extends ServiceImpl<GoodsInfoMapper2, GoodsInfo2> implements GoodsInfoService2 {

    @Autowired
    private GoodsInfoMapper2 goodsInfoMapper2;

    /**
     * 条件分页查询
     *
     * @param @return
     */
    @Override
    public PageResult<GoodsInfo2> ConditionFindPage(findGood findGood) {

        Page page = new Page<>(findGood.getCurrent(),findGood.getSize());

        QueryWrapper queryWrapper = new QueryWrapper<>();

        if (findGood.getGoodId()!=null){
            queryWrapper.eq("good_id",findGood.getGoodId());
        }
        if (StringUtils.hasLength(findGood.getGoodName())){
            queryWrapper.like("good_name",findGood.getGoodName());
        }
        if (StringUtils.hasLength(findGood.getGoodModel())){
            queryWrapper.like("good_model",findGood.getGoodModel());
        }
        if (findGood.getGoodColorid()!=null){
            queryWrapper.like("good_colorid",findGood.getGoodColorid());
        }
        if (findGood.getGoodBrandid()!=null){
            queryWrapper.like("Good_brandid",findGood.getGoodBrandid());
        }

        //查询
        Page<GoodsInfo2> goodsInfo2Page = goodsInfoMapper2.selectPage(page,queryWrapper);

        List<GoodsInfo2> goodsInfo2s = goodsInfo2Page.getRecords();

        long total = goodsInfo2Page.getTotal();

        return new PageResult<GoodsInfo2>(total,goodsInfo2s);
    }
}
